Bug 1548985 Comment 7 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

The assertion-failure is inside of this clause:

```

  if (!mContent->GetParent()) {
    // We're the root of the outermost browsing context, so we need to scale
    // cbSize by the full-zoom so that SVGs with percentage width/height zoom:
[...]
    // We also need to honour the width and height attributes' default values
    // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
    // doesn't report these since there's no such thing as a percentage
    // intrinsic size.  Also note that explicit percentage values are mapped
    // into style, so the following isn't for them.)
[...]
    if (width.IsPercentage()) {
      MOZ_ASSERT(!intrinsicSize.width,
                 "GetIntrinsicSize should have reported no intrinsic width");
      float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
      intrinsicSize.width.emplace(std::max(val, 0.0f) *
                                  cbSize.Width(aWritingMode));
    }
```

As noted in the second comment there, this code is assuming that a percent width or height attribute (the default value) will produce "Nothing()" for our intrinsic size in that dimension.  And if this is a SVG Document (i.e. if our SVG Element is the root element), then we replace that Nothing value with an actual intrinsic size that is based on the viewport size.

The assertion was failing in this case because `contain:size` unconditionally gives this element an intrinsic size with `Some(0)` instead of `Nothing()`. (Note that `intrinsicSize.width` is "truthy" when it is Some(0), so fails the `MOZ_ASSERT(!intrinsicSize.width,...)` check here.  And opt builds trip over a `MOZ_RELEASE_ASSERT` in the `.emplace(...)` call, because you can only `.emplace()` an empty `Maybe<>` object.)

Really, it's silly of us to pretend the intrinsic size is 0,0 in this case where the SVG is the outermost element, because (a) it's not really "replaced", and (b) there's no outer context that we could "contain"/hide our internal sizing from.

So, let's just avoid applying this `contain:size` 0,0-intrinsic-size behavior to outer SVG elements.

(This is a special case for SVG -- i.e. I don't think we need the same behavior for other content -- because SVG is the only element which can either be a replaced element or can be the root element in a document.)
The assertion-failure is inside of this clause:

```

  if (!mContent->GetParent()) {
    // We're the root of the outermost browsing context, so we need to scale
    // cbSize by the full-zoom so that SVGs with percentage width/height zoom:
[...]
    // We also need to honour the width and height attributes' default values
    // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
    // doesn't report these since there's no such thing as a percentage
    // intrinsic size.  Also note that explicit percentage values are mapped
    // into style, so the following isn't for them.)
[...]
    if (width.IsPercentage()) {
      MOZ_ASSERT(!intrinsicSize.width,
                 "GetIntrinsicSize should have reported no intrinsic width");
      float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
      intrinsicSize.width.emplace(std::max(val, 0.0f) *
                                  cbSize.Width(aWritingMode));
    }
```
https://searchfox.org/mozilla-central/rev/99a2a5a955960b0e58ceade1db1f7652d9db4ba1/layout/svg/nsSVGOuterSVGFrame.cpp#295-296,308-323

As noted in the second comment there, this code is assuming that a percent width or height attribute (the default value) will produce "Nothing()" for our intrinsic size in that dimension.  And if this is a SVG Document (i.e. if our SVG Element is the root element), then we replace that Nothing value with an actual intrinsic size that is based on the viewport size.

The assertion was failing in this case because `contain:size` unconditionally gives this element an intrinsic size with `Some(0)` instead of `Nothing()`. (Note that `intrinsicSize.width` is "truthy" when it is Some(0), so fails the `MOZ_ASSERT(!intrinsicSize.width,...)` check here.  And opt builds trip over a `MOZ_RELEASE_ASSERT` in the `.emplace(...)` call, because you can only `.emplace()` an empty `Maybe<>` object.)

Really, it's silly of us to pretend the intrinsic size is 0,0 in this case where the SVG is the outermost element, because (a) it's not really "replaced", and (b) there's no outer context that we could "contain"/hide our internal sizing from.

So, let's just avoid applying this `contain:size` 0,0-intrinsic-size behavior to outer SVG elements.

(This is a special case for SVG -- i.e. I don't think we need the same behavior for other content -- because SVG is the only element which can either be a replaced element or can be the root element in a document.)
The assertion-failure is inside of this clause:

```

  if (!mContent->GetParent()) {
    // We're the root of the outermost browsing context, so we need to scale
    // cbSize by the full-zoom so that SVGs with percentage width/height zoom:
[...]
    // We also need to honour the width and height attributes' default values
    // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
    // doesn't report these since there's no such thing as a percentage
    // intrinsic size.  Also note that explicit percentage values are mapped
    // into style, so the following isn't for them.)
[...]
    if (width.IsPercentage()) {
      MOZ_ASSERT(!intrinsicSize.width,
                 "GetIntrinsicSize should have reported no intrinsic width");
      float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
      intrinsicSize.width.emplace(std::max(val, 0.0f) *
                                  cbSize.Width(aWritingMode));
    }
```

As noted in the second code-comment's parenthetical there, this code is assuming that a percent width or height attribute (the default value) will produce "Nothing()" in our `GetIntrinsicSize()` output, in that dimension.  And if this is a SVG Document (i.e. if our SVG Element is the root element), then we replace that Nothing value with an actual intrinsic size that is based on the viewport size.

The assertion was failing in this case because `contain:size` unconditionally gives this element an intrinsic size with `Some(0)` instead of `Nothing()`. (Note that `intrinsicSize.width` is "truthy" when it is Some(0), so fails the `MOZ_ASSERT(!intrinsicSize.width,...)` check here.  And opt builds trip over a `MOZ_RELEASE_ASSERT` in the `.emplace(...)` call, because you can only `.emplace()` an empty `Maybe<>` object.)

Really, it's silly of us to pretend the intrinsic size is 0,0 in this case where the SVG is the outermost element, because (a) it's not really "replaced", and (b) there's no outer context that we could "contain"/hide our internal sizing from.

So, let's just avoid applying this `contain:size` 0,0-intrinsic-size behavior to outer SVG elements.

(This is a special case for SVG -- i.e. I don't think we need the same behavior for other content -- because SVG is the only element which can either be a replaced element or can be the root element in a document.)
The assertion-failure is inside of this clause:

```

  if (!mContent->GetParent()) {
    // We're the root of the outermost browsing context, so we need to scale
    // cbSize by the full-zoom so that SVGs with percentage width/height zoom:
[...]
    // We also need to honour the width and height attributes' default values
    // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
    // doesn't report these since there's no such thing as a percentage
    // intrinsic size.  Also note that explicit percentage values are mapped
    // into style, so the following isn't for them.)
[...]
    if (width.IsPercentage()) {
      MOZ_ASSERT(!intrinsicSize.width,
                 "GetIntrinsicSize should have reported no intrinsic width");
      float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
      intrinsicSize.width.emplace(std::max(val, 0.0f) *
                                  cbSize.Width(aWritingMode));
    }
```

As noted in the second code-comment's parenthetical there, this code is assuming that a percent width or height attribute (the default value) will produce "Nothing()" in our `GetIntrinsicSize()` output, in that dimension.  And if this is a SVG Document (i.e. if our SVG Element is the root element), then we replace that Nothing value with an actual intrinsic size that is based on the viewport size.

The assertion was failing in this case because `contain:size` unconditionally gives this element an intrinsic size with `Some(0)` instead of `Nothing()`. (Note that `intrinsicSize.width` is "truthy" when it is Some(0), so fails the `MOZ_ASSERT(!intrinsicSize.width,...)` check here.  And opt builds trip over a `MOZ_RELEASE_ASSERT` in the `.emplace(...)` call, because you can only `.emplace()` an empty `Maybe<>` object.)

Really, it's silly of us to pretend the intrinsic size is 0,0 in this case where the SVG is the outermost element, because
 (a) it's not really "replaced" (it contains the whole document - it's not behaving as an element in another external document)
 (b) there's no outer context that we could "contain"/hide our internal sizing from, so it'd be odd to have special `contain:size` sizing behavior on this outermost node.

So, let's just avoid applying this `contain:size` 0,0-intrinsic-size behavior to outer SVG elements.

(This is a special case for SVG -- i.e. I don't think we need the same behavior for other content -- because SVG is the only element which can either be a replaced element or can be the root element in a document.)
The assertion-failure is inside of this clause:

```

  if (!mContent->GetParent()) {
    // We're the root of the outermost browsing context, so we need to scale
    // cbSize by the full-zoom so that SVGs with percentage width/height zoom:
[...]
    // We also need to honour the width and height attributes' default values
    // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
    // doesn't report these since there's no such thing as a percentage
    // intrinsic size.  Also note that explicit percentage values are mapped
    // into style, so the following isn't for them.)
[...]
    if (width.IsPercentage()) {
      MOZ_ASSERT(!intrinsicSize.width,
                 "GetIntrinsicSize should have reported no intrinsic width");
      float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
      intrinsicSize.width.emplace(std::max(val, 0.0f) *
                                  cbSize.Width(aWritingMode));
    }
```

As noted in the second code-comment's parenthetical there, this code is assuming that a percent width or height attribute (the default value) will produce "Nothing()" in our `GetIntrinsicSize()` output, in that dimension.  And if this is a SVG Document (i.e. if our SVG Element is the root element), then we replace that Nothing value with an actual intrinsic size that is based on the viewport size.

The assertion was failing in this case because `contain:size` unconditionally gives this element an intrinsic size with `Some(0)` instead of `Nothing()`. (Note that `intrinsicSize.width` is "truthy" when it is Some(0), so fails the `MOZ_ASSERT(!intrinsicSize.width,...)` check here.  And opt builds trip over a `MOZ_RELEASE_ASSERT` in the `.emplace(...)` call, because you can only `.emplace()` an empty `Maybe<>` object.)

Really, it's silly of us to pretend the intrinsic size is 0,0 in this case where the SVG is the outermost element, because
 (a) it's not really "replaced" (it contains the whole document - it's not behaving as an element in another external document)
 (b) there's no outer context that we could "contain"/hide our internal sizing from, so it'd be odd to have special `contain:size` sizing behavior on this outermost node.

So, let's just avoid applying this `contain:size` 0,0-intrinsic-size behavior to outer SVG elements if they're the root of the document.

(This is only something we have to worry about for SVG -- i.e. I don't think we need the same behavior for other content -- because `<svg>` is the only element which can either be a replaced element or can be the root element in a document.)

Back to Bug 1548985 Comment 7